package com.gsit.ocrbatch.services;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.gsit.ocrbatch.controller.MessageProcesser;
import com.gsit.ocrbatch.domain.MessageConfig;
import com.gsit.ocrbatch.domain.Record;

@Repository
public class MessageConfigService {
	
	@PersistenceContext
	private EntityManager entityManager;
	
	private List<MessageConfig> getMessageConfig(){
		return entityManager.createNamedQuery("findMessageConfigByAll", MessageConfig.class).getResultList();
	}
	
	
	public void send(Record record){
		
		for (MessageConfig messageConfig :  getMessageConfig()) {
			try {
				new MessageProcesser(record, messageConfig).execute();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
	}
	
	

}
